package pers.huangyuhui.sms.service.impl;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Service;
import pers.huangyuhui.sms.mapper.TeacherMapper;
import pers.huangyuhui.sms.model.TeacherInfo;
import pers.huangyuhui.sms.service.TeacherService;
import pers.huangyuhui.sms.util.MyBatisUtil;

import java.util.List;
import java.util.Map;

@Service(value = "teacherService")
public class TeacherServiceImpl implements TeacherService {

    private SqlSession sqlSession = MyBatisUtil.getSqlSession();

    private TeacherMapper teacherMapper = sqlSession.getMapper(TeacherMapper.class);

    /**
     * @param name     教师姓名
     * @param password 密码
     * @return {@code teacherInfo}类型的数据
     */
    @Override
    public TeacherInfo getUserInfo(String name, String password) {
        return teacherMapper.getUserInfo(name, password);
    }

    /**
     * @param teacherInfo 教师信息
     * @return {@code boolean}类型,添加成功后返回{@code true},否则返回{@code false}
     */
    @Override
    public boolean addTeacher(TeacherInfo teacherInfo) {
        return teacherMapper.addTeacher(teacherInfo);
    }

    /**
     * @param map 该哈希表中应含有分页信息{@code paging.start},{@code paging.size}
     *            <p>教师信息{@code teacherInfo.id},{@code teacherInfo.classId},{@code teacherInfo.name}
     * @return {@code boolean}类型,添加成功后返回{@code true},否则返回{@code false}
     */
    @Override
    public List<TeacherInfo> getTeacherList(Map<String, Object> map) {
        return teacherMapper.getTeacherList(map);
    }

    /**
     * @param teacherInfo 教师信息
     * @return {@code Integer}类型的列表总长
     */
    @Override
    public Integer getTeacherListNum(TeacherInfo teacherInfo) {
        return teacherMapper.getTeacherListNum(teacherInfo);
    }

    /**
     * @param teacherInfo 教师信息
     * @return {@code boolean}类型,修改成功后返回{@code true},否则返回{@code false}
     */
    @Override
    public boolean editTeacherInfo(TeacherInfo teacherInfo) {
        return teacherMapper.editTeacherInfo(teacherInfo);
    }

    /**
     * @param ids 由将被删除的教师{@code id}组成的数组
     * @return {@code boolean}类型,删除成功后返回{@code true},否则返回{@code false}
     */
    @Override
    public boolean deleteTeacher(String[] ids) {
        return teacherMapper.deleteTeacher(ids);
    }

    /**
     * @param map 该哈希表中应含有{@code teacherInfo}类型的教师信息,以及新设定的密码{@code newPassword}
     * @return {@code boolean}类型,修改成功后返回{@code true},否则返回{@code false}
     */
    @Override
    public boolean modifyPassword(Map<String, Object> map) {
        return teacherMapper.modifyPassword(map);
    }
}
